package com.hxzy.controller.front.contamer;

import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.BCrypt;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hxzy.common.enums.AckCode;
import com.hxzy.common.resp.R;
import com.hxzy.controller.front.contamer.req.FrontContamerReq;
import com.hxzy.entity.Contamer;
import com.hxzy.service.ContamerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.sql.Struct;

/**
 * @Author wy
 * @Description TODO
 * @Date 2023/9/25 14:49
 * @Version 1.0
 */
@Api(tags = "手机端-前端用户")
@RestController
@RequestMapping(value = "/front/contamer")
public class ContamerController {

    @Autowired
    private ContamerService contamerService;

    @ApiOperation(value = "账号是否被占用")
    @GetMapping(value = "/account/exists")
    public R findAccountCount(String loginid){
        if(StrUtil.isBlank(loginid)){
            return R.build(AckCode.USER_PARAM_IS_NOT_NULL);
        }
        String reg="0?(13|15|17|18|14|19)[0-9]{9}";
        boolean match = ReUtil.isMatch(reg, loginid);
        if(!match){
            return R.build(AckCode.PHONE_NUMBER_ERROR);
        }

        long count=this.contamerService.accountCount(loginid);
        //未被使用
        if(count==0){
            return R.ok();
        }else{
            return R.okHasData("账号被使用");
        }
    }

    @ApiOperation(value = "用户注册")
    @PostMapping(value = "/register")
    public R register(@RequestBody @Valid FrontContamerReq req){
        boolean save=this.contamerService.register(req);
        return save? R.ok(): R.build(AckCode.DATABASE_ERROR);
    }
}
